package com.ynny.Dao.Impl;

import com.ynny.Dao.HobbyDao;
import com.ynny.Entity.Hobby;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class HobbyDaoImpl implements HobbyDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public Hobby findHobbyByNumber(String number) {
        String sql = "select * from hobby where number = ?";
        return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Hobby.class), number);
    }

    @Override
    public int addHobby(Hobby hobby) {
        String sql = "insert into hobby(number,hobby) values(?,?)";
        return jdbcTemplate.update(sql, hobby.getNumber(), hobby.getHobby());
    }
}
